#------------------------------
# Standard CMake Stuff
#------------------------------

cmake_minimum_required (VERSION 2.8)
project (minecraft)   

#------------------------------
# Project Setup
#------------------------------

SET ( VERSION "0.1" )

SET ( INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dist/ )

message(${INSTALL_DIR})

SET ( EXECUTABLE_OUTPUT_PATH ${INSTALL_DIR}/bin )
SET ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${INSTALL_DIR}/lib )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" )

#------------------------------
# Configure build options
#------------------------------

OPTION ( DEBUG "Build binaries with highly verbose output" ON )

#------------------------------
# Process include and link directories
#------------------------------

# Windows should have OGRE in it's environment variables so we can simply
# add the modules relative to it
if(WIN32)
	set( CMAKE_MODULE_PATH "$ENV{OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH}" )
	set( OGRE_SAMPLES_INCLUDEPATH $ENV{OGRE_HOME}/Samples/include )
endif(WIN32)
 
# Same as on windows, only that we guess the corresponding directories
# Path has been teste on Gentoo, changes may be nessecary for other 
# distributions
if(UNIX)
	if(EXISTS "/usr/local/lib/OGRE/cmake")

	  set(CMAKE_MODULE_PATH "/usr/local/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}")
	  set(OGRE_SAMPLES_INCLUDEPATH "/usr/local/share/OGRE/samples/Common/include/") # We could just *assume* that developers uses this basepath : /usr/local

	elseif(EXISTS "/usr/lib/OGRE/cmake")

	  set(CMAKE_MODULE_PATH "/usr/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}")
	  set(OGRE_SAMPLES_INCLUDEPATH "/usr/share/OGRE/samples/Common/include/") # Otherwise, this one

	else (EXISTS "/usr/local/lib/OGRE/cmake")
	  message(SEND_ERROR "Failed to find module path.")
	endif(EXISTS "/usr/local/lib/OGRE/cmake")
endif(UNIX)

# Find OGRE, OIS
find_package(OGRE REQUIRED)
find_package(OIS REQUIRED)

# Check for OIS (OIS is required for input)
if(NOT OIS_FOUND)
	message(SEND_ERROR "Failed to find OIS.")
endif()

# Set build flags for all platforms
if (NOT OGRE_BUILD_PLATFORM_IPHONE)
	if (WIN32 OR APPLE)
		set(Boost_USE_STATIC_LIBS TRUE)
	else ()
		# Statically linking boost to a dynamic Ogre build doesn't work on Linux 64bit
		set(Boost_USE_STATIC_LIBS ${OGRE_STATIC})
	endif ()
	if (MINGW)
		# this is probably a bug in CMake: the boost find module tries to look for
		# boost libraries with name libboost_*, but CMake already prefixes library
		# search names with "lib". This is the workaround.
		set(CMAKE_FIND_LIBRARY_PREFIXES ${CMAKE_FIND_LIBRARY_PREFIXES} "")
	endif ()
	set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0" "1.42" "1.42.0" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" )
	# Components that need linking (NB does not include header-only components like bind)
	set(OGRE_BOOST_COMPONENTS thread date_time serialization filesystem)
	find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS})
	if (NOT Boost_FOUND)
		# Try again with the other type of libs
		set(Boost_USE_STATIC_LIBS NOT ${Boost_USE_STATIC_LIBS})
		find_package(Boost COMPONENTS ${OGRE_BOOST_COMPONENTS})
	endif()
	find_package(Boost)
 
	# Set up referencing of Boost
	include_directories(${BOOST_INCLUDE_DIR})
	add_definitions(-DBOOST_ALL_NO_LIB)
	set(OGRE_LIBRARIES ${OGRE_LIBRARIES} ${BOOST_LIBRARIES} "-lboost_system -lboost_thread -lboost_filesystem -lboost_serialization")
endif()

# Add our directories to lib / include path
link_directories ( ${INSTALL_DIR}/lib )
include_directories ( 
	${PROJECT_SOURCE_DIR}/src/ 
	${OIS_INCLUDE_DIRS}
	${OGRE_INCLUDE_DIRS}
	${OGRE_SAMPLES_INCLUDEPATH})

#------------------------------
# Configure project source files
#------------------------------

CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/src/minecraft/config.hpp.in ${CMAKE_SOURCE_DIR}/src/minecraft/config.hpp )

#------------------------------
# Start building the source
#------------------------------

add_subdirectory (src)
